﻿<?php
	include '../inc/conn.php';
	
	session_start();	

	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);
	if (isset($act) && isset($id))
	{
		if ($act == "del"){
			
			$db = new mysql();
			$db->query("select * from eng_file where ID=".$id);
			$row = $db->fetch_assoc();
			
			if(unlink("..".$row['f_path'])){
				echo $row['f_path']." deleted pass";
			}else{
				echo $row['f_path']." delete fail";
			}
			
			$db->delete('eng_file', "id=".$id);
			$db->close();
			
			echo "<script>alert('Data has deleted!!!');window.location='admin_index.php?name=file';</script>";
		}
	}
?>
<div class="container-fluid">
<? if ($_SESSION['user'] != 1){  
	echo '<script>window.location="userinfo.php"</script>';
 } else {
?>
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">管理面板>>文档管控表</h3>
    </div>
    <div class="panel-body">
	<div>
		<table border=0 cellpadding=0 class="table table-striped">
		<tr class="success"><th>文件名</th><th>文件描述</th><th>位置(点击下载)</th><th>文件状态</th><th>上传</th><th>日期</th><th>操作</th></tr>
<?
		$db = new mysql();
		$db->query("select * from eng_file ORDER BY f_date DESC");
		$num = $db->db_num_rows();
		for($i=0; $i<$num; $i++){
			$row = $db->fetch_assoc();
			$item = $i + 1;
			echo "			<tr>";
			echo "<td>".htmlspecialchars_decode($row['f_name'])."</td>";
			echo "<td>".htmlspecialchars_decode($row['f_desc'])."</td>";
			echo "<td><a href ='http://".$_SERVER['HTTP_HOST'].$row['f_path']."'>".htmlspecialchars_decode($row['f_path'])."</a></td>";
			if (file_exists("..".$row['f_path'])){
				echo "<td><font color='green'>存在</font></td>";
			}else{
				echo "<td><font color='red'>丢失</font></td>";
			}
			echo "<td>".$row['f_owner']."</td>";
			echo "<td>".substr($row['f_date'],0,10)."</td>";
			echo "<td>";
			if (isset($_SESSION['admin']))
				echo "<a href=\"admin_file.php?id=".$row['ID']."&act=del\" rel='tooltip' title='删除表内容，当心哦~~~'><font color='red'><span class=\"glyphicon glyphicon-remove\"></span></font></a></td>";
			echo "</tr>\n";
		}
?>
		</table>
	</div>
</div>
</div>
</div>
<? 
}
	$db->close();
?>
